#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <string.h>
#include <stdio.h>

#include "common.h"
#include "file_process.h"

void send_cmd(const char *c){
	int sock_fd;
	struct sockaddr_in agent_addr;
	struct command cmd; 
	char agent_ip[IP_LENGTH];
	get_agent_ip(agent_ip);

	bzero(&agent_addr, sizeof(agent_addr));
	agent_addr.sin_family = AF_INET;
	agent_addr.sin_port = htons(AGENT_PORT);
	agent_addr.sin_addr.s_addr =inet_addr(agent_ip); 

	cmd.cmd_type=0x01;
	cmd.server_id=get_server_id();
	cmd.cmd_id =get_cmd_id();
	memcpy(cmd.cmd,c,strlen(c)+1);
	gettimeofday(&(cmd.cmd_time),NULL);

	sock_fd=Socket(AF_INET, SOCK_STREAM, 0);

	Connect(sock_fd, (struct sockaddr *)&agent_addr, sizeof(agent_addr));
	Send(sock_fd, &cmd, sizeof(cmd), 0);  

	close(sock_fd);

	write_log(c);
}

int main()
{
	send_cmd("ifconfig");
}
